import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.text.*;
import java.util.*;
import java.io.*;

public abstract class MarkovModel {

  protected int nesym;

  protected static final Random rnd = new Random(1);

  protected Object[] esym;

  protected Map<Object,Integer> esymMap;
 
  public int getSym ( Object sym ) {
        if ( esymMap == null ) {
                esymMap = new HashMap<Object,Integer>();
                for ( int i=0; i<esym.length; i++) esymMap.put(esym[i], i);
        }
        if ( sym instanceof MyObservationVector) sym = ((MyObservationVector)sym).getTrixel();
        Integer aux = esymMap.get(sym);
        if (aux == null) return -1;
        return aux;
  }

  public abstract void print(PrintStream out);

  public static String fmtlog(double x) {
    if (x == Double.NEGATIVE_INFINITY) return fmt.format(0);
    else return fmt.format(Math.exp(x));
  }

  protected static DecimalFormat fmt = new DecimalFormat("0.000000 ");
  protected static String hdrpad = "        ";

}
